package com.hontech.bvapp2.ui.parts.door

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.hontech.bvapp2.R
import com.hontech.bvapp2.device.cp.Door
import com.hontech.bvapp2.ui.dialog.runProgErr
import com.hontech.bvapp2.ui.view.LabelSwitch

class DoorCtrlParts (context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.parts_door_parts_ctrl, this)
        val led1 = view.findViewById<LabelSwitch>(R.id.id_door_parts_ctrl_lsw_led1)
        val led2 = view.findViewById<LabelSwitch>(R.id.id_door_parts_ctrl_lsw_led2)

        led1.onToggleFn = {
            runProgErr("LED1") {
                val ctrl = if (it) 0 else 1
                Door.partsCtrl(1, ctrl)
            }
        }

        led2.onToggleFn = {
            runProgErr("LED2") {
                val ctrl = if (it) 0 else 1
                Door.partsCtrl(2, ctrl)
            }
        }
    }
}